<?php
$host = '0.0.0.0';
$port = 9999;
$listen_socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_bind($listen_socket,$host,$port);
socket_listen($listen_socket);
cli_set_process_title('phpserver master process');

for ($i=1;$i<=2;$i++){
   $pid = pcntl_fork();
   if ($pid==0){
       cli_set_process_title('phpserver worker process');
       while (true){
          $conn_socket = socket_accept($listen_socket);
          $msg = "helloworld\r\n";
          socket_write($conn_socket,$msg,strlen($msg));
          socket_close($conn_socket);
       }
   }
}

while (true){
    sleep(1);
}
socket_close($conn_socket);
